<!DOCTYPE html>
<html class="x-admin-sm">
<head>
<meta charset="UTF-8">
<title>列表</title>
<meta name="renderer" content="webkit">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="format-detection" content="telephone=no">
<link rel="stylesheet" href="/css/font.css">
<link rel="stylesheet" href="/css/index.css">
<script type="text/javascript" src="/layui/layui.js" charset="utf-8"></script>
<script type="text/javascript" src="/js/index.js"></script>
<script type="text/javascript" src="/js/jquery.min.js"></script>
<script type="text/javascript" src="/js/layui-post.js"></script>
</head>
<body>
<div class="x-nav">
	<span class="layui-breadcrumb"><a href="">团购管理</a><a><cite>团购列表</cite></a></span>
    <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" onclick="location.reload()" title="刷新"><i class="layui-icon layui-icon-refresh" style="line-height:30px"></i></a>
</div>
<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-body ">
                    <form class="layui-form layui-col-space5">
		                <div class="layui-inline layui-show-xs-block">
		                    <input type="text" id="actiName" autocomplete="off" value="" placeholder="请输入商品名称" class="layui-input">
		                </div>
                        <div class="layui-inline layui-show-xs-block">
                            <select id="status">
                            	<option value="">请选择活动状态</option>
                                <option value="0">进行中</option>
                                <option value="1">已结束</option>
                            </select>
                        </div>
		                <div class="layui-inline layui-show-xs-block">
		                    <input type="text" id="remark" autocomplete="off" value="" placeholder="请输入活动说明" class="layui-input">
		                </div>
                        <div class="layui-inline layui-show-xs-block">
                            <button class="layui-btn"  lay-submit="" lay-filter="sreach" id="search"><i class="layui-icon">&#xe615;</i></button>
                        </div>
                    </form>
                </div>
                <div class="layui-card-header">
                    <button class="layui-btn" onclick="xadmin.open('新增','./groupactiadd')"><i class="layui-icon layui-icon-add-circle"></i>添加</button>
                	<!--<button class="layui-btn layui-btn-danger" onclick="delAll()"><i class="layui-icon"></i>批量删除</button>-->
                </div>
                <div class="layui-card-body layui-table-body layui-table-main">
                    <table class="layui-table layui-form" id="table" lay-filter="table"></table>
                </div>
            </div>
        </div>
    </div>
</div>
<!-- 物流跟踪 -->
<div class="modal-dialog" id="orderLog" style="font-size:16px;display: none;background: #fff;padding: 30px;">
    <ul class="layui-timeline" id="orderwl"></ul>
</div>
</body>
<script>
$.ajaxSetup({contentType: "application/json; charset=utf-8"});
let checkArr = null;
layui.use(['table','form'], function(){
	var table = layui.table
    table.render({
        elem: 'table', //指定元素
        url:'/cateringGroupActivities/select?token='+sessionStorage.getItem("token"),
        contentType:'application/json',
        method:'post',
        page:true,
        cellMinWidth: 80, //全局定义常规单元格的最小宽度，layui 2.2.1 新增
        where:{orderByAscType: "status",orderByType: "createTime"},
        cols: [[
            //{type: 'checkbox',width: 80},
            {title: '序号',align:"center",halign:"center",width:80,type: 'numbers'},
            {field:'status',align:"center",title:'是否结束',templet:onloadStatus},
            {field:'goodsName',align:"center",title:'商品名称',width:180},
            {field:'actiName',align:"center",title:'拼团名称',width:180},
            {field:'actiPrice',align:"center",title:'活动价格'},
            {field:'groupSize',align:"center",title:'成团人数',},
            {field:'actiNum',align:"center",title:'活动数量',},
            {field:'limitNum',align:"center",title:'限购数量',},
            {field:'actiDesc',align:"center",title:'活动说明',width:280},
            {field:'startTime',align:"center",title: '开始时间',width:150,},
            {field:'endTime',align:"center",title: '结束时间',width:150,},
            {field:'createTime',align:"center",title: '创建时间',width:150,},
            {fixed:'right',align: 'center',title:'操作',width: 80,templet: onloadTool }
        ]],
    })
	layui.table.on('checkbox(table)', function(obj){
		checkArr = null;
	    let checkStatus = table.checkStatus('table'),data = checkStatus.data; //获取选中的数据
	    for (let i = 0; i < data.length; i++) {
	    	checkArr = checkArr != null ? checkArr + "," + data[i].sysId:data[i].sysId;
	    }
	});
    layui.form.on('switch(switchTest)', function(data){
        var id = data.elem.attributes['data_id'].nodeValue;
        var status = data.elem.attributes['status'].nodeValue;
        var em = $(data.othis[0]);
        layer.confirm('确认'+(status == 0 ? '' : '取消')+'结束吗？',{icon: 0,title:'提示',cancel:function(){closeSwitch1(data,status,em);}},function(index){
            if(status == 0) layuiPost(geturl()+'/cateringGroupActivities/update?token='+sessionStorage.getItem("token"),{status:1,sysId:id});
            else layuiPost(geturl()+'/cateringGroupActivities/update?token='+sessionStorage.getItem("token"),{status:0,sysId:id});
        },function(index){
            closeSwitch1(data,status,em)
        });
    });
});
function onloadStatus(data){
    if(data.status == 1){
        return '<input type="checkbox" checked="" name="switch" lay-skin="switch" data_id="'+data.sysId+'" status="'+data.status+'" lay-filter="switchTest" lay-text="是|否">'
    }else if(data.status == 0){
        return '<input type="checkbox" name="switch" lay-skin="switch" data_id="'+data.sysId+'" status="'+data.status+'" lay-filter="switchTest" lay-text="是|否">'
    }
}
/*删除*/
function member_del(obj,id){
    layer.confirm('确认要删除吗？',function(index){
    	layuiPost(geturl()+'/cateringGroupActivities/delete?token='+sessionStorage.getItem("token"),{sysId:id});
    });
}

$('#search').on('click', function() {
	layui.table.reload('table', {
		page: {curr: 1},
		where : {
            orderByAscType: "status",
            orderByType: "createTime",
            actiName:$("#actiName").val(),
			status:$("#status").val(),
			remark:$("#remark").val(),
		},
	});
	return false;
});
function onloadTool(data) {
    return '<a title="编辑" onclick="xadmin.open(\'编辑\',\'groupactiedit?sysId=' + data.sysId + '\')" href="javascript:;"><i class="layui-icon">&#xe642;</i></a>' +
        '<a title="删除" onclick="member_del(this,\'' + data.sysId + '\')" href="javascript:;"><i class="layui-icon">&#xe640;</i></a>';
}
</script>
</html>